import SwiftUI

struct HomeView: View {
    @EnvironmentObject var authManager: AuthManager
    @State private var showingSettings = false
    
    var body: some View {
        NavigationView {
            VStack(spacing: 20) {
                Image(systemName: "keyboard")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 80, height: 80)
                    .foregroundColor(.blue)
                
                Text("欢迎使用拓客输入法")
                    .font(.title)
                    .fontWeight(.bold)
                
                if let user = authManager.currentUser {
                    VStack(alignment: .leading, spacing: 10) {
                        Text("用户名: \(user.username)")
                        Text("邮箱: \(user.email)")
                    }
                    .padding()
                    .background(Color(.systemGray6))
                    .cornerRadius(8)
                }
                
                VStack(spacing: 15) {
                    NavigationLink(destination: Text("词库管理").font(.largeTitle)) {
                        HStack {
                            Image(systemName: "book")
                            Text("词库管理")
                            Spacer()
                            Image(systemName: "chevron.right")
                        }
                        .padding()
                        .background(Color(.systemGray6))
                        .cornerRadius(8)
                    }
                    
                    NavigationLink(destination: Text("输入设置").font(.largeTitle)) {
                        HStack {
                            Image(systemName: "gear")
                            Text("输入设置")
                            Spacer()
                            Image(systemName: "chevron.right")
                        }
                        .padding()
                        .background(Color(.systemGray6))
                        .cornerRadius(8)
                    }
                    
                    NavigationLink(destination: Text("皮肤主题").font(.largeTitle)) {
                        HStack {
                            Image(systemName: "paintbrush")
                            Text("皮肤主题")
                            Spacer()
                            Image(systemName: "chevron.right")
                        }
                        .padding()
                        .background(Color(.systemGray6))
                        .cornerRadius(8)
                    }
                }
                .padding(.horizontal)
                
                Spacer()
                
                VStack(spacing: 10) {
                    Text("如何启用键盘:")
                        .font(.headline)
                    
                    Text("1. 打开设备的'设置'应用")
                    Text("2. 前往'通用' > '键盘' > '键盘'")
                    Text("3. 点击'添加新键盘'")
                    Text("4. 在'第三方键盘'下选择'拓客输入法'")
                    Text("5. 点击'拓客输入法'并启用'允许完全访问'")
                }
                .font(.caption)
                .padding()
                .background(Color(.systemGray6))
                .cornerRadius(8)
                .padding(.horizontal)
            }
            .padding()
            .navigationBarItems(
                trailing: Button(action: {
                    showingSettings = true
                }) {
                    Image(systemName: "person.circle")
                        .imageScale(.large)
                }
            )
            .sheet(isPresented: $showingSettings) {
                SettingsView()
                    .environmentObject(authManager)
            }
        }
    }
}